<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
//  return new Set([...setA, ...setB]);  
  

//交集
function intersection(setA, setB) {  
    debugger
 const result = new Set();  
 for (let item of setA) {  
 if (setB.has(item)) {  
 result.add(item);  
 }  
 }  
 return result;  
}  

// 差集
function difference(setA, setB) {  
 const result = new Set();  
 for (let item of setA) {  
 if (!setB.has(item)) {  
 result.add(item);  
 }  
 }  
 return result;  
}  

// 子集检查
function isSubset(setA, setB) {  
 for (let item of setA) {  
 if (!setB.has(item)) {  
 return false;  
 }  
 }  
 return true;  
}  

//读取输入并进行集合操作的主函数
function performSetOperations() {  
 const inputA = prompt("请输入集合 A (逗号分隔):").split(',').map(Number);  
 const inputB = prompt("请输入集合 B (逗号分隔):").split(',').map(Number);  
 const setA = new Set(inputA);  
 const setB = new Set(inputB);  
 const unionResult = union(setA, setB);  
 const intersectionResult = intersection(setA, setB);  
 const differenceResult = difference(setA, setB);  
 const isSubsetResult = isSubset(setA, setB);  
 console.log("并集:", Array.from(unionResult));  
 console.log("交集:", Array.from(intersectionResult));  
 console.log("差集:", Array.from(differenceResult));  
 console.log("A 是否是 B 的子集:", isSubsetResult);  
}
  

// 调用主函数
performSetOperations();




    </script>
</body>
</html>